package com.niodata.dt.fs;

import java.io.IOException;
import java.util.Map;

import org.apache.hadoop.fs.FileSystem;

public interface FileSystemBuilder {

  /**
   * create fileSystem.
   *
   * @param user user
   * @param type fs type
   * @param config config
   * @return fs
   */
  static FileSystem createFileSystem(String user,
        FileSystemType type,
        Map<String, String> config) throws IOException {
    FileSystemBuilder builder = newBuilder(type);
    return builder.createFileSystem(user, config);
  }


  FileSystem createFileSystem(String user, Map<String, String> config) throws IOException;



  /**
   * new file system builder.
   * @param dsType fs type
   * @return fs builder
   */
  public static FileSystemBuilder newBuilder(FileSystemType dsType) {
    FileSystemBuilder builder = null;
    switch (dsType) {
      case SFTP:
        builder = new SftpFileSystemBuilder();
        break;
      case FTP:
        builder = new FtpFileSystemBuilder();
        break;
      case NFS:
        throw new RuntimeException("nfs not implemented");
      case OBS:
        builder = new ObsFileSystemBuilder();
        break;
      case OSS:
        builder = new OssFileSystemBuilder();
        break;
      case HDFS:
        builder = new HdfsFileSystemBuilder();
        break;
      case LOCAL:
        builder = new LocalFileSystemBuilder();
        break;
      case LOCAL_REL:
        builder = new RelLocalFileSystemBuilder();
        break;
      case US3:
        builder = new Us3FileSystemBuilder();
        break;
      case S3:
        builder = new S3FileSystemBuilder();
        break;
      case HTTP:
        builder = new HttpFileSystemBuilder();
        break;
      default:
        break;
    }
    return builder;
  }

}
